Skip to content

feat(web): add run_server orchestration entry point#110

Merged
kimit0310 merged 2 commits into
devfrom
feature/server-entry
May 13, 2026
Merged

feat(web): add run_server orchestration entry point#110
kimit0310 merged 2 commits into
devfrom
feature/server-entry

Conversation

@kimit0310
Copy link
Copy Markdown
Collaborator

Resolves #105

Adds run_server so the app actually starts a WebSocket server and broadcaster when you run mobi-view.

run_server(presenter, host, port) serves as the single sync entry point that wires everything together. It calls asyncio.run(_run_server_async()).

_run_server_async creates a Broadcaster, starts its background thread, opens the websockets server with the existing ws_handler and process_request hooks already in place, then blocks until the process receives SIGINT or SIGTERM. On shutdown, it stops the broadcaster and closes the server cleanly through the normal finally path.

_register_shutdown_signals uses loop.add_signal_handler to set an asyncio.Event when either SIGINT or SIGTERM is received. The server awaits that event inside the async with server.serve() context, so cleanup flows through finally path.

main.py now calls run_server instead of printing a placeholder message. schedule_browser_launch fires before the blocking run_server call so the browser opens at http://localhost:8765 once the server is up.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev@9b8771f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/MoBI_View/main.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##             dev     #110   +/-   ##
======================================
  Coverage       ?   99.08%           
======================================
  Files          ?        8           
  Lines          ?      327           
  Branches       ?        0           
======================================
  Hits           ?      324           
  Misses         ?        3           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kimit0310 kimit0310 marked this pull request as ready for review April 13, 2026 15:27
@kimit0310 kimit0310 requested a review from Asanto32 April 13, 2026 15:29
Copy link
Copy Markdown
Collaborator

@Asanto32 Asanto32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small things to clean up. Can you test _run_server_async directly and then do the outer loop to test run_server?

Args:
presenter: The MainAppPresenter providing stream data.
host: The hostname to bind to.
port: The port to listen on.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on why the default is 8765? seems like a default tcp port?

Comment thread src/MoBI_View/main.py
logger.info("Note: Web server functionality will be added in future branch")

schedule_browser_launch()
web_server.run_server(presenter)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this does something should we add a smoke test for main to check we actually open the web page (which has nothing in it right?)

Comment thread tests/unit/test_server.py Outdated
mock_serve.__aenter__ = AsyncMock()
mock_serve.__aexit__ = AsyncMock(return_value=False)

async def _run() -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially replacing your _run_server_async right?

Comment thread tests/unit/test_server.py Outdated
_, serve_kwargs = mock_serve_fn.call_args
assert serve_kwargs["process_request"] is server.process_request

asyncio.run(_run())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call this directly instead of your function that calls asyncio.run?

@kimit0310 kimit0310 requested a review from Asanto32 April 13, 2026 19:41
@kimit0310 kimit0310 merged commit 00ab557 into dev May 13, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants